package cl.blueprintsit.utils;

import java.util.List;

public class ListUtils {

    /**
     * This method is responsible for converting a list into a CSV style String.
     *
     * @param collection The collection to be converted.
     * @return A CSV string representing the given <code>collection</code>.
     */
    public static <T> String toCSV(List<T> collection) {
        String result = "";

        for (T element : collection) {
            result += element + ",";
        }

        /* The last comma is removed (if there is one)! */
        if (!result.equals("")){
            return result.substring(0, result.length()-1);
        }

        return result;
    }
}
